package org.example.aop;

import lombok.extern.apachecommons.CommonsLog;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;

import java.net.BindException;
import java.util.UUID;

@Aspect
@Component
public class TraceLogAspect {

    private static final String  TRACE_ID = "TRACE_ID";

    @Before("@annotation(org.example.annotation.TraceLog)")
    public void beforeMethodExcution(){
        String tid = UUID.randomUUID().toString();
        MDC.put(TRACE_ID, tid);

    }

    @After("@annotation(org.example.annotation.TraceLog)")
    public void afterMethodExcution(){
        MDC.remove(TRACE_ID);
    }
}
